package com.sinosoft.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.sinosoft.base.BaseFormController;
import com.sinosoft.base.Constants;
import com.sinosoft.data.ZywxImage0Manager;
import com.sinosoft.product.ZywxImage0;
import com.sinosoft.util.DisplayGetPage;

@Controller
@RequestMapping("/zywximage/zywxImage0Edit.html")
public class ZywxImage0Controller extends BaseFormController {
	
	private ZywxImage0Manager zgr = null;

	@Autowired
	public void setZgr(ZywxImage0Manager zgr) {
		this.zgr = zgr;
	}
	

	//查询列表
	@RequestMapping(params = "method=list", method = RequestMethod.GET)
	public ModelAndView select(Model model, HttpServletRequest request) {
		String page = DisplayGetPage.getPageParamName("zywxImage0", request);// 第几页
		ZywxImage0 zywx0 = new ZywxImage0();
		List zywx0List = null;
		
		int pagesize = zgr.getPagesize(zywx0);
		zywx0List = zgr.getZywxImage0List((Integer.parseInt(page) - 1)
				* Constants.pagesize, Constants.pagesize, zywx0);
		model.addAttribute("resultSize", pagesize);

		double size = Constants.pagesize;
		model.addAttribute("displayallpage", Math.ceil(pagesize / size));
		model.addAttribute("thispage", Integer.parseInt(page));

		ZywxImage0 zyIm = new ZywxImage0();
		
		model.addAttribute("ZywxImage0", zyIm);

		model.addAttribute("ptmeth", "list");
		
		

		return new ModelAndView("zywximage/zywxImage0list",
				Constants.LEVEL_0_MODEL, zywx0List);

	
     }
	
	//select  列表展示
	@RequestMapping(params = "method=select")
	public ModelAndView selectlist(ZywxImage0 zywx0,Model model,HttpServletRequest request){
		List zywxImage0 = null;
		HttpSession session = request.getSession(true);
		if(null == zywx0.getSensorid()&& null == zywx0.getSatelliteid() ){
			ArrayList zywxlist = (ArrayList)session.getAttribute("zywximagelistSession");
			zywx0.setSensorid(String.valueOf(zywxlist.get(0)));
			zywx0.setSatelliteid(String.valueOf(zywxlist.get(1)));
		}else{
			
			ArrayList zylist = new ArrayList();
			zylist.add(zywx0.getSensorid());
			zylist.add(zywx0.getSatelliteid());
			session.setAttribute("zywximagelistSession", zylist);
		}
		
		String page = DisplayGetPage.getPageName("zywxImage0", request);//第几页
		
		int pagesize = zgr.getPagesize(zywx0);
		
		zywxImage0 = zgr.getZywxImage0List((Integer.parseInt(page) - 1)* Constants.pagesize, Constants.pagesize, zywx0);
		
		request.setAttribute("resultSize", pagesize);
		model.addAttribute("zywxImage0", zywx0);
		
		double size = Constants.pagesize;
		
		model.addAttribute("displayallpage", Math.ceil(pagesize
				/ size));
		model.addAttribute("thispage", Integer.parseInt(page));

		model.addAttribute("ptmeth", "select");
		
		
		
		return new ModelAndView("zywximage/zywxImage0list",Constants.LEVEL_0_MODEL, zywxImage0)  ;
	}
	
	//删除操作
	@RequestMapping(params = "method=delete",method = RequestMethod.GET)
	public String delete(BigDecimal scenenum,HttpServletRequest request){
		
		zgr.removeZywxImage0(scenenum);
		
		String page  = request.getParameter("tz");
		
		String pagename = DisplayGetPage.getPageName("zywxImage0", request);//第几页
		
		String postmethod = request.getParameter("ptemth");
		
		return "redirect:/zywximage/zywxImage0Edit.html?method=list&" + pagename + "=" + page;
	}
	//进入编辑页面
	@RequestMapping(params = "method = inedit")
	public String showForm(BigDecimal scenenum ,HttpServletRequest request,Model model,HttpServletResponse response)throws Exception{
		
		ZywxImage0 zywx0 = new ZywxImage0();
		if("null".equals(scenenum) || null == scenenum){
			
		}else{
			zywx0 = zgr.getZywxImage0ById(scenenum);
			
		}
		
		//将翻页参和查询方式传到编辑页面
		String page =request.getParameter("tz");
		String pagename = DisplayGetPage.getPageName("zywxImage0", request);
		
		model.addAttribute("tzpage", page);
		model.addAttribute("pagename", pagename);
		model.addAttribute("ptmeth", request.getParameter("ptmeth"));
		model.addAttribute("ZywxImage0", zywx0);
		return "zywximage/zywxImage0Edit";
	}
	
	
	//添加修改
	@RequestMapping(params = "method = edit")
	public String edit(ZywxImage0 zywx0 ,HttpServletRequest request){
			
		try{
				zgr.saveZywxImage0(zywx0);
			}catch(Exception e){
				e.printStackTrace();
			}
		String pagename = request.getParameter("pagename");
		String page = request.getParameter("tz");
		if("".equalsIgnoreCase(page)){
			page = "1";
		}
		String postmethod = request.getParameter("ptmeth");
		return "redirect:/zywximage/zywxImage0Edit.html?method=list&" + pagename + "=" + page;
	}
	
	//进入详情查看
	
	@RequestMapping(params = "method = ineditXq")
	public String showFormXq(BigDecimal scenenum ,HttpServletRequest request,Model model,HttpServletResponse response)throws Exception{
		
		ZywxImage0 zywx0 = new ZywxImage0();
		if("null".equals(scenenum) || null == scenenum){
			
		}else{
			zywx0 = zgr.getZywxImage0ById(scenenum);
			
		}
		
		//将翻页参和查询方式传到编辑页面
		String page =request.getParameter("tz");
		String pagename = DisplayGetPage.getPageName("zywxImage0", request);
		
		model.addAttribute("tzpage", page);
		model.addAttribute("pagename", pagename);
		model.addAttribute("ptmeth", request.getParameter("ptmeth"));
		model.addAttribute("ZywxImage0", zywx0);
		return "zywximage/zywx0CkList";
		 
  }

	
}